// Copyright 2007 Google, Inc. All Rights Reserved.

package com.google.jessewilson.codesearch.intellij.dfs;

import com.google.jessewilson.codesearch.api.CodeFile;
import com.google.jessewilson.codesearch.io.Path;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.openapi.vfs.VirtualFileListener;

import java.io.File;
import java.io.IOException;

/**
 * A filesystem representing files downloaded from a code search service.
 *
 * @author jessewilson
 */
public class DownloadedFileSystem extends VirtualFileSystem {

  private static final String PROTOCOL = "CodeSearch";
  private DownloadedDirectory root = new DownloadedDirectory(this, Path.fromString("/"));


  public String getProtocol() {
    return PROTOCOL;
  }

  public DownloadedFile addFile(CodeFile codeFile, File localFile) {
    DownloadedFile downloadedFile = new DownloadedFile(this, root, codeFile,
        localFile);
    root.addChild(downloadedFile);
    return downloadedFile;
  }

  public DownloadedFile getFile(CodeFile codeFile) {
    return root.getChild(codeFile);
  }

  public VirtualFile findFileByPath(String path) {
    return null;
  }

  public void refresh(boolean asynchronous) {
    // do nothing
  }

  public VirtualFile refreshAndFindFileByPath(String path) {
    return null;
  }

  public void forceRefreshFiles(final boolean asynchronous,
      VirtualFile... files) {
    // do nothing
  }

  protected void deleteFile(Object requestor, VirtualFile vFile)
      throws IOException {
    throw new UnsupportedOperationException();
  }

  protected void moveFile(Object requestor, VirtualFile vFile,
      VirtualFile newParent) throws IOException {
    throw new UnsupportedOperationException();
  }

  protected void renameFile(Object requestor, VirtualFile vFile, String newName)
      throws IOException {
    throw new UnsupportedOperationException();
  }

  protected VirtualFile createChildFile(Object requestor, VirtualFile vDir,
      String fileName) throws IOException {
    throw new UnsupportedOperationException();
  }

  protected VirtualFile createChildDirectory(Object requestor, VirtualFile vDir,
      String dirName) throws IOException {
    throw new UnsupportedOperationException();
  }

  public void addVirtualFileListener(VirtualFileListener listener) {
    // do nothing, this filesystem is not observable
  }

  public void removeVirtualFileListener(VirtualFileListener listener) {
    // do nothing, this filesystem is not observable
  }

  protected VirtualFile copyFile(Object requestor, VirtualFile virtualFile, VirtualFile newParent, String copyName) throws IOException {
    throw new UnsupportedOperationException();
  }

  public boolean isReadOnly() {
    return true;
  }
}
